/*
* Copyright (c) 2008-2011, Thomas Handorf
* 
* This file is part of libScopes.
* libScopes is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
* 
* libScopes is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
* 
* You should have received a copy of the GNU Lesser General Public License
* along with libScopes.  If not, see <http://www.gnu.org/licenses/>.
*/

template< typename T > struct serialization_info{ 
    static const bool is_serializable = false; 
    static const bool is_pointer = false; 
}; 

template< typename T > T new_from_pointer(){ // dummy, not needed
   return T();
}
template< typename T > T* new_from_pointer(){ //this creates a new referenced object whenever you do a T* x=new_from_pointer()
   return new T();
}

//specific implementations for classes that support serialization methods

template <class T> class array; // predeclare array


template<typename T> struct serialization_info<array<T> >{ 
   static const bool is_serializable = true; 
   static const bool is_pointer = false; 
}; 
template<typename T> struct serialization_info<array<T>*>{ 
   static const bool is_serializable = true; 
   static const bool is_pointer = true; 
}; 

   
// serialization methods


template <class T> void do_serialize(T& obj,string& str){
//   size_t len=sizeof(T);
//   str.append((char*) &len,sizeof(len));
   str.append((char*) &obj,sizeof(T));
}
template <class T> void do_serialize(T* obj,string& str){
   size_type len=0;
   string str2=new string();
   if (obj){
      if (serialization_info<T>::is_serializable){
         obj->serialize(str2);
         len=str2->length();
         str.append((char*) &len,sizeof(len)); 
         str.append(str2,pos);
      } else {
         str.append((char*) &len,sizeof(len)); // len=0 if no deserialization available
      }
   } else {
      str.append((char*) &len,sizeof(len)); // len=0 if null ptr
   }
}
template <class T> T& do_deserialize(string& str,size_t& pos){
   T obj;
   str.copy((char*) &obj,sizeof(T),pos);
   pos+=sizeof(T);
   return T;
}
template <class T> T* do_deserialize(string& str,size_t& pos){
   T* obj=new T();
   size_type len=0;
   str.copy((char*) &len,sizeof(len),pos);
   if (len){
      obj=
   } else {
   }
   return obj;
}
   template <class T> void array<T>::deserialize(string& str,size_type& pos){
   /*   size_type len;
   str.copy((char*) &len,sizeof(len),pos);
   pos+=sizeof(len);
   this->clear();
   this->resize(len);
   size_type i;
   if (serialization_info<T>::is_serializable){
      for (i=0;i<len;i++){
         if (serialization_info<T>::is_pointer){
            (*this)[i]=new_from_pointer();
            (*this)[i]->deserialize(str,pos);
} else {
   (*this)[i].deserialize(str,pos);
}
}
} else {
   str.copy((char*) &(this->front()),len*sizeof(T),pos);
   pos+=len*sizeof(T);
}*/
}
